package base.stream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

// 字节数组流
public class ByteArrayStreamDemo {
    public static void main(String[] args) {
        // 1. 创建源
        byte[] srcData = "abcdefg".getBytes();

        ByteArrayInputStream inputStream = new ByteArrayInputStream(srcData);
        int data = inputStream.read();

        while (data != -1) {
            System.out.printf(String.valueOf((char) data));
            data = inputStream.read();
        }

        System.out.println("/n");

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(121212);

        byte[] outputData =  outputStream.toByteArray();
        System.out.println(outputData);

    }
}
